package org.crackjack.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Category that can have many appointments.
 * One appointment can have just one category.
 * Example of category:
 * health,household services
 * 
 * @author Dmitry Kalachov
 * 
 */
@Entity
@Table(name = "categories")
public class Category extends Identify implements Serializable {

    private static final long serialVersionUID = -8534447526785295863L;
    private String name;
    private List<Appointment> appointments;

    public Category() {

    }

    @Column(name = "name", nullable = false, unique = true)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "category", fetch = FetchType.LAZY)
    public List<Appointment> getAppointments() {
        return appointments;
    }

    public void setAppointments(List<Appointment> appointments) {
        this.appointments = appointments;
    }

    @Override
    @Id
    @GeneratedValue
    @Column(name = "id")
    public Long getId() {
        return super.getId();
    }

}
